import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);


const routes = [
    // {
    //     path: '*',
    //     redirect: '/main'
    // },
    {
        path: '/main',
        component: () => import('@/views/main/index.vue'),
        meta: {
            title: '首页疫情'
        }
    },
    {
        path: '/user',
        component: () => import('@/views/user/index.vue'),
        meta: {
            title: '个人中心'
        }
    },
    {
        path: '/news',
        component: () => import('@/views/news/index.vue'),
        meta: {
            title: '疫情动态'
        }
    },
    {
        path: '/fire',
        component: () => import('@/views/plague/HomeIndex.vue'),
        meta: {
            title: '疫情'
        }
    },
    {
        path: '/device-api',
        component: () => import('@/views/user/device-api.vue'),
        meta: {
            title: '原生API演示'
        }
    },
];

// add route path
routes.forEach(route => {
    route.path = route.path || '/' + (route.name || '');
});

const router = new Router({routes});

router.beforeEach((to, from, next) => {
    const title = to.meta && to.meta.title;
    if (title) {
        document.title = title;
    }
    next();
});

export {
    router
};
